package com.shajj.movie;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Text;
import com.shajj.movie.subtitle.SubtitleSearchJanitor;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Subtitle implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 使用shooter的id
     */
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Long id;

    /**
     * IMDB编号
     */
    @Persistent
    private Long imdbNum;

    /**
     * 字幕分段信息
     */
    @Persistent
    private String part;

    /**
     * 电影名称
     */
    @Persistent
    private Text title;

    /**
     * 电影名称搜索分词
     */
    @Persistent
    private Set<String> fts;

    /**
     * 评分
     */
    @Persistent
    private Integer score;

    /**
     * 格式
     */
    @Persistent
    private String format;

    /**
     * 语言
     */
    @Persistent
    private String language;

    /**
     * 校订
     */
    @Persistent
    private String revision;

    /**
     * 调校
     */
    @Persistent
    private String adjust;

    /**
     * 来源
     */
    @Persistent
    private String source;

    /**
     * 查看数
     */
    @Persistent
    private Long viewNum;

    /**
     * 上传用户
     */
    @Persistent
    private String uploader;

    /**
     * 下载数
     */
    @Persistent
    private Long downloadNum;

    /**
     * 下载地址
     */
    @Persistent
    private String downloadLink;

    /**
     * 字幕文件名
     */
    @Persistent
    private String fileName;

    /**
     * 字幕文件大小
     */
    @Persistent
    private String fileSize;

    /**
     * 上传时间
     */
    @Persistent
    private Date time;

    public Subtitle(Long id, String title) {
        this.id = id;
        this.fts = new HashSet<String>();
        this.title = new Text(title);

        SubtitleSearchJanitor.updateFTSStuffForThread(this);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title.getValue();
    }

    public void setTitle(String content) {
        this.title = new Text(content);
    }

    public String getTimeString() {
        return ShajjUtil.DateFormat(time);
    }

    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public void setFts(Set<String> fts) {
        this.fts = fts;
    }

    public Set<String> getFts() {
        return fts;
    }

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public String getRevision() {
		return revision;
	}

	public void setRevision(String revision) {
		this.revision = revision;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public Long getViewNum() {
		return viewNum;
	}

	public void setViewNum(Long viewNum) {
		this.viewNum = viewNum;
	}

	public String getUploader() {
		return uploader;
	}

	public void setUploader(String uploader) {
		this.uploader = uploader;
	}

	public Long getDownloadNum() {
		return downloadNum;
	}

	public void setDownloadNum(Long downloadNum) {
		this.downloadNum = downloadNum;
	}

	public String getDownloadLink() {
		return downloadLink;
	}

	public void setDownloadLink(String downloadLink) {
		this.downloadLink = downloadLink;
	}

	public void setTitle(Text title) {
		this.title = title;
	}

	public String getAdjust() {
		return adjust;
	}

	public void setAdjust(String adjust) {
		this.adjust = adjust;
	}

	public Long getImdbNum() {
		return imdbNum;
	}

	public void setImdbNum(Long imdbNum) {
		this.imdbNum = imdbNum;
	}

	public String getPart() {
		return part;
	}

	public void setPart(String part) {
		this.part = part;
	}

	public Integer getScore() {
		return score;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFileSize() {
		return fileSize;
	}

	public void setFileSize(String fileSize) {
		this.fileSize = fileSize;
	}

	@Override
	public String toString() {
		return "Subtitle [id=" + id + ", time=" + time + ", title=" + title.getValue() + "]";
	}
}
